<?php
/**
 * My new Zend Framework project
 * 
 * @Soroosh 
 * @version 
 * 
 * Hier wird die Konfiguration der PHP-Umgebung und die Konfiguration
 * der Zend Framework-Umgebung bearbeitet
 * 
 */


// Pfäde definieren
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); 
defined('APPLICATION_BASE') || define('APPLICATION_BASE', realpath(dirname(__FILE__) . '/..'));
defined('APPLICATION_PUBLIC') || define('APPLICATION_PUBLIC', realpath(dirname(__FILE__) . '/../public'));
defined('APPLICATION_HTDOCS') || define('APPLICATION_HTDOCS', realpath(dirname(__FILE__) . '/../..'));

// bekanntgabe des Zend Framework Library 
set_include_path(
APPLICATION_HTDOCS.'/library/Zend_1.9.3/'.PATH_SEPARATOR.
APPLICATION_HTDOCS.'/library/'.PATH_SEPARATOR.
get_include_path());


/**
 * Automatische Klassen Loader von Zend und Somi Lib
 */
require_once APPLICATION_HTDOCS."/library/Zend_1.9.3/Zend/Loader/Autoloader.php";
$autoloader=Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('Somi');
$autoloader->setFallbackAutoloader(true);
// Laden die Formular aus dem Somi Lib

require_once APPLICATION_HTDOCS.'/library/Somi/Form/Kontakt.php';
require_once APPLICATION_HTDOCS.'/library/Somi/Form/SubTestForm.php';
require_once APPLICATION_HTDOCS.'/library/Somi/Form/SubForm.php';
require_once APPLICATION_HTDOCS.'/library/Somi/Form/BewerbenForm.php';
require_once APPLICATION_HTDOCS.'/library/Somi/Form/Login.php';
require_once APPLICATION_HTDOCS.'/library/Somi/Form/jobi.php';


// Locale auf Deutsche Sprache und Datum,... umsetzen
Zend_Registry::set('Zend_Locale',new Zend_Locale('de_DE'));

//Definieren einer Standard-Zeitzone
date_default_timezone_set('Europe/Berlin');



// Zend_Cache
$optionFront= array(
'lifetime'					=>1800,
'automatic_serialization'	=>true
);

$optionBack= array(
'cach_dir'	=> APPLICATION_BASE.'/data/cache/'
);
$cache = Zend_Cache::factory('Core','File',$optionFront,$optionBack);
Zend_Registry::set('cache',$cache);

// Session Optionen erstellen und starten.
$sessionConfig=array(
	'use_only_cookies' => true,
	'remember_me_seconds'=> 120,
	'name'				=> 'somi_session',
	'save_path'			=> APPLICATION_BASE.'/data/sessions/',
);
Zend_Session::start($sessionConfig);


//-- Layouts aktivieren
Zend_Layout::startMvc(array('layoutPath' => APPLICATION_PATH.'/default/layouts','layout' => 'main'));

//-- Dojo auf jeder seite Aktivieren, Dojo Funktioniert mit der Layout zusammen.
Zend_Dojo::enableView(Zend_layout::getMvcInstance()->getView());



// Konfiguration Routers laden
#$routconfig=new Zend_Config_Ini(APPLICATION_PATH.'/default/config/routerconfig.ini','routes');
#$router=new Zend_Controller_Router_Rewrite();
#$router->addConfig($routconfig);
#Zend_Registry::set('route',$router);


// definiere den  Entwiklungsumgebung anhand des Servernames.
if($_SERVER['HTTP_HOST']=='localhost')
{
	define('APPLICATION_ENVIROMENT','development');
}else{
	define('APPLICATION_ENVIROMENT','production');
}

// Konfiguration Datenbank laden
$config=new Zend_Config_Ini(APPLICATION_PATH.'/default/config/config.ini',APPLICATION_ENVIROMENT);
Zend_Registry::set('config',$config);

// Datenbank starten
$db=Zend_Db::factory($config->db->adapter,$config->db->params->toArray());
$db->query("SET NAMES utf8");
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('db',$db);

// Zend_Log in eine Logdatei
$logger=new Zend_Log();
$logger->addWriter(new Zend_Log_Writer_Stream(APPLICATION_BASE . '/data/logs/log.txt'));
Zend_Registry::set('logger', $logger);

// Zend_Log in einer Datenbank
#$tableName= 'user';
#$columnMapping= array(
#	'user_login'=> 'timestamp',
#	'user_logout'=> 'timestamp',
#);

#$loggerDb=new Zend_Log();
#$loggerDb->addWriter(new Zend_Log_Writer_Db($db,$tableName,$columnMapping));
#$loggerDb->info('testts');


// Zend Session Starten
Zend_Session::start();


// Acl Objekt instanzieren
#$auth = Zend_Auth::getInstance();
#$acl  = new Somi_Acl_Acl();



/**
 * Initialisieren von FrontController
 */
$frontController = Zend_Controller_Front::getInstance();

$frontController->setDefaultModule('default');
#$frontController->setControllerDirectory( array(
#'default'		=> APPLICATION_PATH.'/default/controllers',
#'administrator'		=> APPLICATION_PATH.'/administrator/controllers',
#'operator'		=> APPLICATION_PATH.'/opeartor/controllers',
#'gast'		=> APPLICATION_PATH.'/gast/controllers',
#));
$frontController->addModuleDirectory(APPLICATION_PATH);
#$frontController->setBaseUrl('/personal');
$frontController->getBaseUrl();
#$frontController->registerPlugin(new Somi_Auth_AccessControl($auth, $acl));
$frontController->registerPlugin(new Somi_Plugin_ModuleSetup());
#$frontController->registerPlugin(new Somi_Plugin_Predispatch());
$frontController->throwExceptions(true);
$frontController->dispatch(); 



function _initNavigation()
{
	$this->bootstrap('layout');
	$layout = $this->getResource('Layout');
	$view = $layout->getView();
	
	// Navigation Config
	$confignav = new Zend_Config_Xml(APPLICATION_PATH.'/default/config/navigation.xml','nav');
	$nav = new Zend_Navigation($confignav);
	$view->navigation($nav);	
}



?>